package mainFragment.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.xuegengwang.xuegengwang.R;

import java.util.List;

import view.MyImageLoader;

/**
 * Created by Administrator on 2017/3/23.
 */

public class MyGridViewAdapter extends BaseAdapter {
    private static final String TAG = "MyGridViewAdapter";
    private List<String> urls;
    private Context context;

    public MyGridViewAdapter(Context context,List<String> urls) {
        this.urls = urls;
        this.context = context;
    }

    @Override
    public int getCount() {
        if (urls != null) {
            return urls.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final MyHolder myHolder;
        if (convertView == null) {
            myHolder = new MyHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.topicadapter_gridview_item, null);
            myHolder.topicadapter_gridview_item_ima = (ImageView) convertView.findViewById(R.id.topicadapter_gridview_item_ima);
            convertView.setTag(myHolder);
        } else {
            myHolder = (MyHolder) convertView.getTag();
        }
        if(!TextUtils.isEmpty(urls.get(position))) {
            MyImageLoader.showImage(urls.get(position), myHolder.topicadapter_gridview_item_ima);
        }
        else{
            myHolder.topicadapter_gridview_item_ima.setVisibility(View.GONE);
        }
        return convertView;
    }

    class MyHolder {
        ImageView topicadapter_gridview_item_ima;
    }
}